package com.demo.controller;

import com.alibaba.fastjson.JSON;
import com.demo.function.spring.resolver.ReplaceRequestHeaderMethodArgumentResolver;
import com.demo.model.entity.es.OrderHeader;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试请求头控制器
 * @author K
 */
@Slf4j
@RestController
public class RequestHeaderController {

    /**
     * 获取请求header的指定value，并自动转换成对象，实现转换的Resolver是{@link ReplaceRequestHeaderMethodArgumentResolver}
     * @param orderHeader 请求头参数
     * @return 订单号
     */
    @GetMapping("/get/header/order/orderSn")
    public String getHeaderOrderSn(@RequestHeader("order") OrderHeader orderHeader) {
        log.info(JSON.toJSONString(orderHeader));
        return orderHeader.getOrderSn();
    }
}
